<?php
include 'connect.php';

if (isset($_POST['name'])) {

	$name = $_POST['name'];

	if ($name != "") {
		mysql_query("INSERT INTO category (id, name) VALUES (null, '".$name."')")  or die(mysql_error()); 
	}
}

$data = mysql_query("SELECT * FROM category")  or die(mysql_error()); 
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ASMO-708">
<link href="css/style_demo.css" type="text/css" rel="stylesheet">
<script type="text/javascript" src="js/jquery-1.7.1.min.js"></script>
<title>New Site Domain Title</title>
</head>
<body>
<div id="container">
	
	
	<div id="main">
		<div class="submit-form">
			<form action="add_category.php" method="post" enctype="multipart/form-data">
			<table width="100%" cellpadding="0" cellspacing="0">
				<thead>
					<tr>
						<td colspan="2"><div class="title-form">Add Form</div></td>
					</tr>
				</thead>
				<tbody>
					<tr>
						<td width="30%" class="name">name</td>
						<td><input type="text" name="name" value=""></td>
					</tr>
					<tr class="dotline">
						<td></td>
						<td>
							<button type="submit">Add</button>
						</td>
					</tr>
				</tbody>
			</table>
			</form>
		</div>
		
		<br />
		
		<div class="submit-form">
			<table width="100%" cellpadding="0" cellspacing="0">
				<thead>
					<tr>
						<td colspan="2"><div class="title-form">List category</div></td>
					</tr>
				</thead>
				<tbody>
					<tr>
						<td>Id</td>
						<td>Name</td>
					</tr>
					<?php
					while($category = mysql_fetch_array( $data )) 
					{ 
					?>
					<tr>
						<td width="30%" class="name"><?=$category['id']?></td>
						<td><?=$category['name']?></td>
					</tr>
					<?php
					}
					?>
				</tbody>
			</table>
		</div>
	</div>
	
</div>
</body>
</html>